﻿using System;
using LightINI;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static LightINI.Ini;

namespace LightINIUnitTest
{
    [TestClass]
    public class UnitTest1
    {
        private readonly Ini ini;

        public UnitTest1()
        {
            ini = Open("test.ini");
        }

        [TestMethod]
        public void TestMethod1()
        {
            Assert.AreEqual(2, ini.Count, "共有配置段数量");
        }
        [TestMethod]
        public void TestMethod11()
        {
            var section = ini.Get("section1");
            Assert.AreEqual(4, section.Count, "section1 共有配置项数量: 4");
        }

        [TestMethod]
        public void TestMethod2()
        {
            var section = ini.Get("section1");
            var name = "selcetable-item-with-default";
            Assert.AreEqual("value4-0", section.Get(name).Value, "配置段section1 -> selcetable-item-with-default 值为 value4-0");

            section.Set(name, "value4-2");
            ini.Save("test1.ini");
        }

        [TestMethod]
        public void TestMethod3()
        {
            ini.Get("section3", true);

            Assert.IsNotNull(ini.Get("section3"), "获取section3");

            Assert.AreEqual(3, ini.Count, "自动添加了段section3,现在共有3个配置段");
        }

        [TestMethod]
        public void TestMethod4()
        {
            Assert.AreEqual("value1", ini.Get("section1").Get("normal-item").Value, "第一个配置项的值");
        }

        [TestMethod]
        public void TestMethod5()
        {
            Assert.IsNull(ini.Get("section1").Get("commented-item"), "第二个配置项是null");
        }
    }
}
